using UnityEngine;
using System.Collections;

public class Server : MonoBehaviour {
	public Transform player, pCam;
	public Transform[] players;
	public int index = 0;
	void Start () {
		DontDestroyOnLoad(transform.gameObject);
		Network.InitializeServer(3,25001,false);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnServerInitialized(){
		SpawnPlayer(Network.player);
	}
	void OnPlayerConnected(NetworkPlayer newPlayer){
		SpawnPlayer(newPlayer);
	}
	void SpawnPlayer(NetworkPlayer newPlayer){
		index += 1;
		int pNum = int.Parse(newPlayer+"");
		Transform newT = (Transform)Network.Instantiate(player,new Vector3(0,20,0),transform.rotation,0);
		NetworkView nView = newT.networkView;
		nView.RPC("SetPlayer",RPCMode.AllBuffered, newPlayer);
		players[pNum] = newT;
	}
	void OnPlayerDisconnected(NetworkPlayer player){
		index -= 1;
		players[int.Parse(player+"")] = null;
		Network.RemoveRPCs(player,0);
		Network.DestroyPlayerObjects(player);
	}
	
}
